package com.slipper.qmt.task;

import com.slipper.sfts.order.service.DealerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Consumer extends Thread {
    private static final Logger logger = LoggerFactory.getLogger(Consumer.class);

    private boolean shutdown = false;
    private final TaskList taskList;

    public Consumer(TaskList taskList) {
        this.taskList = taskList;
    }

    public void run() {
        while (!shutdown) {
            try {
                Object data = this.taskList.consume();
                logger.info("接收到消息：{}", data);
                DealerFactory.doDeal(data);
                logger.info("消息已处理：{}", data);
            } catch (InterruptedException e) {
                logger.error("从消息队列中获取数据失败！", e);
            }
        }
    }

    public void shutdown() {
        this.shutdown = true;
    }
}
